const PropModel = require("../../models/PropModel")
const WebUserModel = require("../../models/WebUserModel")

const PropService ={
    
    add:async({propname,propnumber,propemail,building,roomnumber,roomarea})=>{
        return PropModel.create({
            propname,propnumber,propemail,building,roomnumber,roomarea
        })
    },

    getList:async({id})=>{//{}是查询所有记录，【】是要的字段
        return id?PropModel.find({_id:id},["propname","propnumber","propemail","building","roomnumber","roomarea"]): 
        PropModel.find({},["propname","propnumber","propemail","building","roomnumber","roomarea"])
    },
    delList:async ({_id})=>{
        return PropModel.deleteOne({_id})
    },
    putList:async(body)=>{//{}是查询所有记录，【】是要的字段
        return PropModel.updateOne({_id:body._id},body)
    },
    addaccount:async({username,password,propname,building,roomnumber})=>{
        return WebUserModel.create({username,password,propname,building,roomnumber})
    },
    getaccount:async({id})=>{
        return id?WebUserModel.find({_id:id},[]): 
        WebUserModel.find({},[])
    },
    putaccount:async(body)=>{
        return WebUserModel.updateOne({_id:body._id},body)
    },
    delaccount:async ({_id})=>{
        return WebUserModel.deleteOne({_id})
    },
}

module.exports =PropService